package ntut.andengine.physics;

import javax.microedition.khronos.opengles.GL10;

import ntut.andengine.game.GameLevel;

import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsConnector;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.bitmap.BitmapTexture;
import org.anddev.andengine.opengl.texture.bitmap.BitmapTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;

public class Wall extends PhysicalComponent {

	public Wall(GameLevel level) {
		super(level);
		
		this.mBitmapTexture = new BitmapTexture(64, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		TextureRegion whiteWallTextureRegion = BitmapTextureRegionFactory.createFromAsset(this.mBitmapTexture, level, "20x20.png", 0, 0);
		//TextureRegion redWallTextureRegion = BitmapTextureRegionFactory.createFromAsset(this.mBitmapTexture, level, "ice_wall.png", 20, 0);
		//TextureRegion blueWallTextureRegion = BitmapTextureRegionFactory.createFromAsset(this.mBitmapTexture, level.getContext(), "xxx.png", 40, 0);
		level.getEngine().getTextureManager().loadTexture(this.mBitmapTexture);	
		
		mSprite = new Sprite(0, 0, whiteWallTextureRegion);
		mSprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
		
		FixtureDef fixtureDef = PhysicsFactory.createFixtureDef(1, 0, 0);
		mBody = PhysicsFactory.createBoxBody(level.getPhysicsWorld(), mSprite, BodyType.StaticBody, fixtureDef);
		mBody.setUserData(new ContactEvent("Wall"){

			@Override
			public void beginContact(Body body, Vector2 Normal) {
				
			}

			@Override
			public void endContact(Body body, Vector2 Normal) {
				
			}});
		
		level.getScene().attachChild(mSprite);
		level.getPhysicsWorld().registerPhysicsConnector(new PhysicsConnector(mSprite, mBody, true, true));
	}

}
